<template>
  <el-select v-model="value" :placeholder="props.placeholder" clearable filterable @change="change">
    <el-option v-for="item in warehouseOptions" :key="item.id" :label="item.warehouse_name" :value="item.id" />
  </el-select>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";
const commonStore = useCommonStore();
const warehouseOptions = computed(() => {
  if (!commonStore.warehouseFilterOptions) {
    commonStore.getWarehouseFilterList()
  }
  return commonStore.warehouseFilterOptions
});

const props = defineProps({
  modelValue: [Number, String, Array],
  placeholder: {
    type: String,
    default: '请选择',
  }
});

const value = computed(() => {
  return props.modelValue
})

const emit = defineEmits(['update:modelValue', 'change'])
const change = (val) => {
  const item = warehouseOptions.value.find(i => i.id == val)
  emit('update:modelValue', val)
  emit('change', item?.warehouse_name)
}

</script>